#ifndef SETTINGS_H
#define SETTINGS_H

#include <QList>
#include <QMap>
#include <QPair>
#include <QSettings>
#include <QString>
#include <QVariant>

class QScriptEngine;

#include "defines.h"

class Settings
{
public:
    enum ProxyConfigKind
    {
        PCK_UndefinedProxyConfig,
        PCK_NoProxy,
        PCK_SystemProxy,
        PCK_ManualProxy
    };


    enum Parameter {
        // Saved using QSettings

        //  +-- generic settings
        LogFilePath,

        //   +-- symbian settings
        QtEnvBatPath,
        FullS60SDK,
        UID3,
        PanningEnabled,
        TextSelectionEnabled,
        WidgetLayout,
        LastWidgetPath,
        LastDirectoryPath,

        //  +-- maemo5 settings
        MaddePath,
        HybridAuthor,
        HybridEmail,
        Licence,
        HybridShortDesc,
        HybridLongDesc,

        //  +-- network settings
        ForumNokiaUserName,
        ProxyConfig,
        ProxyUrl,
        ProxyPort,
        ProxyUserName,
        ProxyPassword,

        //  +-- remote compiler persisted properties
        RcProperties,

        // Pseudo-settings, not saved using QSettings

        //  +-- symbian settings
        ShowFullScreen,
        ShowSoftKeys,
        QtVersion,
        QtVersionString
    };

    enum LayoutMode {
        StatusPaneWithSoftKeys = 0,
        FullScreenWithSoftKeys = 1,
        FullScreenWithoutSoftKeys = 2
    };

public:
    static Settings& instance()
    {
      static Settings singleton;
      return singleton;
    }

    /**
      * Gets the value for a key.
      *
      * Some settings are meant to be application (app name)
      * specific. In that case the final key used is the
      * concatenation of the app and key ("APP/KEY"), if app
      * is not NULL.
      *
      * @param key the key for the value to get
      *
      * @param app application name for app specific settings.
      * If given, then the app specific value for the key will
      * be returned. If defined, it should be a alphadigitial
      * ASCII string (no blanks).
      *
      * @return the value stored for the key (or <app,key> pair)
      * if app was given.
      */
    static QVariant get(Parameter   key,
                        QString     app = QString(""));

    /**
      * Sets a value for a key, possibly application specific.
      *
      * See comments for get().
      *
      */
    static void set(Parameter   key,
                    QVariant    value,
                    QString     app = QString(""));
    static void setTemporary(Parameter key, QVariant value);



    /**
      * Utility function using 'RcProperties'.
      *
      * This method loads the uninterpreted string for
      * RcProperties from settings and parses it. It
      * provides a map of (OS platform identifiers, OS
      * OS platorm human readable description) items that are
      * supported by the remote compiler.
      *
      * @param scriptEngine the engine to use for parsing
      */
    typedef QMap<QString, QString> OsDescMap;
    static OsDescMap RcOSes(QScriptEngine & scriptEngine);

    /**
      * Utility function using 'RcProperties'.
      *
      * This method loads the uninterpreted string of
      * RcProperties from settings and parses it. It
      * provides a list of (OS, Qt, WccParam) pairs. The OS
      * identifiers are the same as returned by method
      * 'RcOses'.
      *
      * @param scriptEngine the engine to use for parsing
      */
    struct OsQtPair
    {
        QString m_os;
        QString m_qt;

        OsQtPair(QString os,
                 QString qt);
        /**
          * The wccparam to be encluded in URLs to remote compiler
          * targetting this particular OS with this particular Qt
          * version. Like "pSet[os]=maemo5&pSet[qt]=4_6_2".
          */
        QString wccParams() const;
    };
    typedef QList<OsQtPair> OsQtPairList;
    static OsQtPairList RcOsQtPairs(QScriptEngine & scriptEngine);

    /**
      * @return true if Forum Nokia user name and proxy configuration
      *         are defined in settings.
      */
    static bool IsRcConfigured();

private:
    Settings();
    ~Settings();

    Settings(const Settings&); // No copy
    Settings& operator=(const Settings&); // No assignment
    QSettings* getSettingObject();
    static QString getKey(Parameter       key,
                          const QString & app);

    QString guessQtEnvPath() const;
    QString guessMobilityPath() const;

private:
    QSettings *m_settings;
    QMap<Settings::Parameter, QVariant> *m_overridingSettings;
    QString m_error;

};

#endif // SETTINGS_H
